import router from '@/router';
import { useUserStore } from '@/stores/user';

// 路由加载前
router.beforeEach(async (to, _from, next) => {
  const userStore = useUserStore();

  // 如果是登录页面
  if (to.path === '/login') {
    if (userStore.isLoggedIn) {
      next('/home');
    } else {
      next();
    }
  } else {
    // 非登录页面
    if (userStore.isLoggedIn) {
      next();
    } else {
      next('/login');
    }
  }
});

// 路由加载后
router.afterEach(() => {});
